package javaEEBasic.day02;

import java.util.Random;
import java.util.Scanner;

public class Test03 {
    public static void main(String[] args) {
        double income = 200000;
        double[] tax = personalIncomeTax(income);
        System.out.println("税率:" + tax[0]*100 + "%");
        System.out.println("应纳税：" + tax[1]);
    }

    public static void method1() {

        System.out.println("天天开心");

    }

    public static String fun2() {
        return "this is fun2";
    }


    public static void method2() {

        System.out.println("代码so easy!");

    }


    public static int method3() {

        return 3 * 5;

    }

    public static void test01() {
        //静态数组初始化方式
        int[] arr = new int[]{1, 2, 3, 4, 5};
        //简化写法
        int[] arr1 = {1, 2, 3, 4, 5};
        //这种可以，但不推荐
        int arr2[] = {1, 2, 3, 4, 5};
        System.out.println(arr); //数组是引用数据类型，arr存储的是数组的起始地址
        //动态数组初始化方式 先不赋值，只给除数据类型和数组长度
        double[] arr3 = new double[5];
        //不能混用,静态初始化和动态初始化的写法是独立的，不能混用，会报错
        //double[] arr4 = new double[5]{1.1, 2.2, 3.3, 4.4, 5.5};、
    }

    public static void test02() {
        int[] arr = {10, 20, 30, 40, 50};
        System.out.println("arr[2]：" + arr[2]);
        int[] arr1 = new int[5];
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = i * 10 + 60;
        }
        for (int i = 0; i < arr1.length; i++) {
            System.out.println("arr1[" + i + "]：" + arr1[i]);
        }
    }

    public static void test03() {
        Scanner sc = new Scanner(System.in);
        int[] scores = new int[5];
        int sum = 0;
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生的成绩：");
            scores[i] = sc.nextInt();
            sum += scores[i];
        }
        System.out.println("平均分:" + sum / scores.length);
    }

    public static void test04() {
        double[] arr = {12.9, 53.54, 75.0, 99.1, 3.14};
        double min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println(min);
    }

    public static void test05() {
        double arr[] = {10.4, -3, -6.2, 1.2, -6.1, -19, -3.8, 0.9, -4.5, 5.5};
        int count1 = 0, count2 = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > 0) {
                count1++;
            } else if (arr[i] < 0) {
                count2++;
            }
        }
        System.out.println("赚钱的股票一共有:" + count1 + "只");
        System.out.println("赔钱的股票一共有:" + count2 + "只");
    }

    public static void test06() {
        int[] arr1 = new int[10];
        int[] arr2 = arr1;
        Scanner sc = new Scanner(System.in);
        //1.定义两个数组变量arr1、arr2指向同一个长度为10的整型数组，使用键盘分别录入10个数字，
        // 使用数组arr1保存键盘输入的数字到数组中，遍历数组找出数组的最大值并输出到控制台显示。
        int max = arr1[0];
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = sc.nextInt();
            if (arr1[i] > max) {
                max = arr1[i];
            }
        }
        System.out.println("arr1中的最大值是：" + max);
        //2. 使用数组变量 arr2修改数组的第一个元素为 100，
        // 遍历输出arr2数组保存的数据到控制台显示
        arr2[0] = 100;
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + " ");
        }
    }

    public static void test07() {
        int[] arr1 = {10, 34, 56, 12, 100};
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + " ");
        }
    }

    public static void test08() {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[5];
        int min = arr[0], max = arr[0], sum = 0;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
            sum += arr[i];
            if (arr[i] > max) {
                max = arr[i];
            }
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println("该选手平均分:" + (sum - min - max) / 3);
        sc.close();
    }

    //① 定义一个方法，这个方法的作用是在控制台上打印1~100的数字。
    public static void test09() {
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
        }
    }

    //② 定义一个方法，在这个方法参数里面传递一个随机数字，这个随机数的取值范围是1~100，
    // 随机数生成的是几，程序就计算1到几的数字之和。
    public static int sumN(int n) {
        if (n < 1 || n > 100) {
            throw new RuntimeException("参数错误");
        }
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static double electricCharges(double kwh) {
        if (kwh < 0) {
            throw new RuntimeException("参数错误");
        }
        double charges = 0;
        if (kwh <= 240) {
            charges = 0.4 * kwh;
        } else if (kwh > 240 && kwh <= 400) {
            charges = 0.4 * 240 + 0.5 * (kwh - 240);
        } else {
            charges = 0.4 * 240 + 0.5 * 160 + 0.7 * (kwh - 400);
        }
        return charges;
    }

    //1. 定义一个方法，这个方法接收一个整型数组，返回数组中的最大值。

    public static int maxIntArr(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new RuntimeException("参数错误");
        }
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }

    //② 定义一个有参有返回值的方法，实现随机数组功能（数组元素随机打乱），返回打乱后的随机数组，
    public static int[] randomArr(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new RuntimeException("参数错误");
        }
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            int index = random.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
        return arr;
    }
    //③ 定义一个有参无返回值的方法，实现数组各元素在控制台输出打印功能，格式:"[1,2,3]"

    public static void printArr(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new RuntimeException("参数错误");
        }
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.println(arr[i] + "]");
            } else {
                System.out.print(arr[i] + ",");
            }
        }
    }

    public static int sum(int a, int b) {
        return a + b;
    }

    public static double sum(int a, double b) {
        return a * b;
    }

    public static int  maxCommonDivisor(int a, int b) {
        if(a<0 || b<0) {
            System.out.println("输入的数字不能为0");
            return 0;
        }
        //欧几里得算法（辗转相除法）
        while(b!=0) {
            int temp = a%b;
            a = b;
            b = temp;
        }
         return a;
    }

    //个人所得税率
    public static double[] personalIncomeTax( double income) {
        if (income<=0) {
            throw new RuntimeException("参数错误");
        }
         double[] taxRate = new double[2];
        if(income <= 36000) {
            taxRate[0] = 0.03;
            taxRate[1] = 0;
        } else if( income > 36000 && income  <= 144000)  {
             taxRate[0] = 0.1;
             taxRate[1] = 2520;
        }  else if( income > 144000 && income  <= 300000)  {
             taxRate[0] = 0.2;
              taxRate[1] = 16920;
        } else if( income > 300000 && income  <= 420000)  {
             taxRate[0] = 0.25;
              taxRate[1] = 31920;
        } else if( income > 420000 && income  <= 660000)  {
             taxRate[0] = 0.3;
             taxRate[1] = 52920;
        } else if( income > 660000 && income  <= 960000) {
             taxRate[0] = 0.35;
              taxRate[1] = 85920;
        }  else if( income > 960000) {
             taxRate[0] = 0.45;
              taxRate[1] = 181920;
        }
         return taxRate;
    }


}
